﻿CREATE FUNCTION [Mapping].[GetSQL_DropRuntimeView]
(
  @viewName nvarchar(50)
)
RETURNS nvarchar(500)
AS
BEGIN
  DECLARE @sql nvarchar(500)

  SET @sql = 
  'IF EXISTS (SELECT * FROM sys.views WHERE [object_id] = OBJECT_ID(''Mapping.[<{ViewName}>]''))
    BEGIN
      DROP VIEW Mapping.[<{ViewName}>]
    END
  '

  SET @sql = REPLACE(@sql, '<{ViewName}>', @viewName)

  RETURN @sql
END
